package com.ruoyi.web.controller.basic;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basic.domain.KaoqinAddress;
import com.ruoyi.basic.service.IKaoqinAddressService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考勤地点管理Controller
 * 
 * @author hyh
 * @date 2021-04-13
 */
@RestController
@RequestMapping("/basic/address")
public class KaoqinAddressController extends BaseController
{
    @Autowired
    private IKaoqinAddressService kaoqinAddressService;

    /**
     * 查询考勤地点管理列表,注释掉权限，从而让别的用户也可以查询(用于考勤记录)
     */
//    @PreAuthorize("@ss.hasPermi('basic:address:list')")
    @GetMapping("/list")
    public TableDataInfo list(KaoqinAddress kaoqinAddress)
    {
        startPage();
        List<KaoqinAddress> list = kaoqinAddressService.selectKaoqinAddressList(kaoqinAddress);
        return getDataTable(list);
    }

    /**
     * 导出考勤地点管理列表
     */
    @PreAuthorize("@ss.hasPermi('basic:address:export')")
    @Log(title = "考勤地点管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(KaoqinAddress kaoqinAddress)
    {
        List<KaoqinAddress> list = kaoqinAddressService.selectKaoqinAddressList(kaoqinAddress);
        ExcelUtil<KaoqinAddress> util = new ExcelUtil<KaoqinAddress>(KaoqinAddress.class);
        return util.exportExcel(list, "address");
    }

    /**
     * 获取考勤地点管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:address:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(kaoqinAddressService.selectKaoqinAddressById(id));
    }

    /**
     * 新增考勤地点管理
     */
    @PreAuthorize("@ss.hasPermi('basic:address:add')")
    @Log(title = "考勤地点管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KaoqinAddress kaoqinAddress)
    {
        return toAjax(kaoqinAddressService.insertKaoqinAddress(kaoqinAddress));
    }

    /**
     * 修改考勤地点管理
     */
    @PreAuthorize("@ss.hasPermi('basic:address:edit')")
    @Log(title = "考勤地点管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KaoqinAddress kaoqinAddress)
    {
        return toAjax(kaoqinAddressService.updateKaoqinAddress(kaoqinAddress));
    }

    /**
     * 删除考勤地点管理
     */
    @PreAuthorize("@ss.hasPermi('basic:address:remove')")
    @Log(title = "考勤地点管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(kaoqinAddressService.deleteKaoqinAddressByIds(ids));
    }
}
